﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DigitalRune.Windows.Docking;
namespace SharpLab
{
    public partial class ChartOptions : DockableForm
    {
        #region Private Deklarationen
        private GraphicForm _GrFrm;

        #endregion

        #region Schnittstelle nach Aussen
        /// <summary>
        /// Objekt der GraphicsForm, für die die Eigenschaften angezeigt bzw. geändert werden sollen.
        /// </summary>
        public GraphicForm GrFrm
        {
            set
            {
                _GrFrm = value;
            }
            get
            {
                return _GrFrm;
            }
        }

        #endregion


        #region Public Methoden

        public ChartOptions()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Aktualisiert die Daten der Eingabefelder
        /// </summary>
        /// <remarks>Eventuell noch als Event realisieren!!!</remarks>
        public void UpdateFields()
        {
            if (GrFrm != null)
            {
                //Titel des Optionsdialogs
                TabText = "Optionen für " + GrFrm.ChartName;
                //Bezeichnung der Diagrammachsen
                tbXLabel.Text = GrFrm.XLabel;
                tbYLabel.Text = GrFrm.YLabel;
                //Achseneinheiten
                tbXUnit.Text = GrFrm.XUnit;
                tbYUnit.Text = GrFrm.YUnit;
                //Maxima, Minima und Skalierung der Achsen
                nudXMin.Value = (decimal)GrFrm.XMin;
                nudXMax.Value = (decimal)GrFrm.XMax;
                nudYmin.Value = (decimal)GrFrm.YMin;
                nudYMax.Value = (decimal)GrFrm.YMax;
                nudXScale.Value = (decimal)GrFrm.XScale;
                nudYScale.Value = (decimal)GrFrm.YScale;
                //Gitternetz
                cbGridHor.Checked = GrFrm.hGrid;
                cbGridVer.Checked = GrFrm.vGrid;
                //Name des Diagramms
                tbChName.Text = GrFrm.ChartName;
                //Mauseinstellungen
                cbMouseCoord.Checked = GrFrm.MouseCoordinates;
            }
        }

        #endregion

        #region Private Methoden
        /// <summary>
        /// Wenn das Fenster den Fokus bekommt werden die Daten aktuallisiert
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void ChartOptions_Enter(object sender, EventArgs e)
        {
            UpdateFields();
        }
        /// <summary>
        /// Horizontales Gitternetz an- oder ausschalten
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void cbGridHor_CheckedChanged(object sender, EventArgs e)
        {
            GrFrm.hGrid = cbGridHor.Checked;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Vertikales Gitternetz an- oder ausschalten
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void cbGridVer_CheckedChanged(object sender, EventArgs e)
        {
            GrFrm.vGrid = cbGridVer.Checked;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Minimalwert der X-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudXMin_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.XMin = (float)nudXMin.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Maximalwert der X-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudXMax_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.XMax = (float)nudXMax.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Skaleneinteilung der X-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudXScale_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.XScale = (float)nudXScale.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Minimalwert der Y-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudYmin_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.YMin = (float)nudYmin.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Maximalwert der Y-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudYMax_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.YMax = (float)nudYMax.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Skaleneinteilung der Y-Achse ändern
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Ereignisargumente</param>
        private void nudYScale_ValueChanged(object sender, EventArgs e)
        {
            GrFrm.YScale = (float)nudYScale.Value;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Die Bezeichnung der X-Achse wird geändert
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbXLabel_Leave(object sender, EventArgs e)
        {
            GrFrm.XLabel = tbXLabel.Text;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Maßeinheit der X-Achse
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbXUnit_Leave(object sender, EventArgs e)
        {
            GrFrm.XUnit = tbXUnit.Text;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Bezeichnung der Y-Achse
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbYLabel_Leave(object sender, EventArgs e)
        {
            GrFrm.YLabel = tbYLabel.Text;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Maßeinheit der Y-Achse
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbYUnit_TextChanged(object sender, EventArgs e)
        {
            GrFrm.YUnit = tbYUnit.Text;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Andert den Namen des Diagramms
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbChName_Leave(object sender, EventArgs e)
        {
            GrFrm.ChartName = tbChName.Text;
            GrFrm.setChartName();
        }
        /// <summary>
        /// Mauskoordinaten an- bzw. ausschalten
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbMouseCoord_CheckedChanged(object sender, EventArgs e)
        {
            GrFrm.MouseCoordinates = cbMouseCoord.Checked;
            GrFrm.Invalidate();
        }
        /// <summary>
        /// Cursor für die X-Achse an- bzw. ausschalten
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbXCursor_CheckedChanged(object sender, EventArgs e)
        {
            GrFrm.XCursor = cbXCursor.Checked;
            GrFrm.Invalidate();
        }
        #endregion
    }
}
